

/**
 * Created with IntelliJ IDEA.
 * Description:二叉树的最大深度
 * User: wangxin
 * Date: 2024-11-06
 * Time: 22:28
 */



   class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;
    public TreeNode(int val) {
      this.val = val;
    }
  }


public class test1 {
    public int maxLen(TreeNode root){
        if(root == null){
            return 0;
        }
        int leftLen =  maxLen(root.left) + 1;
        int rightLen =  maxLen(root.right) + 1;

        int max= Math.max(leftLen,rightLen);
        return max;
    }
    public int maxDepth (TreeNode root) {
        // write code here
        int max =  maxLen(root);
        return max;
    }
}
